/* eslint-disable camelcase */
/*
 * @Description: 档案相关接口
 * @Author: Rfan
 * @Date: 2022-06-16 14:12:26
 * @LastEditTime: 2023-03-09 16:17:51
 */

import request from '@/utils/request';
import type { ICommonParams, ICoordinate, IPageQuery } from '@/interfaces/global';
import { Key } from 'react';

// 分页查询档案条目参数
export interface IFetchArchivesByPageParams extends ICoordinate {
  commonParams: ICommonParams;
}
// 分页查询档案条目
export function fetchArchivesLevelWithPage(data: IPageQuery<IFetchArchivesByPageParams>) {
  return request({
    url: `/archives/page`,
    method: 'post',
    data
  });
}

export interface IRuleSearchParams {
  commonParams: ICommonParams;
  coordinate: ICoordinate;
  fieldName: string;
  fieldValueList: any[];
}
// 根据规则查询档案条目
export function fetchArchivesByRule(data: IRuleSearchParams) {
  return request({
    url: `/archives/list`,
    method: 'post',
    data
  });
}

// 根据目录树节点查询参数
export interface IFetchArchivesByNodeParams {
  commonParams: ICommonParams;
  dirTreeId: 0;
}
// 根据目录树节点ID分页查询
export function fetchArchivesLevelWithPageTree(data: IPageQuery<IFetchArchivesByNodeParams>) {
  return request({
    url: `/archives/page-tree`,
    method: 'post',
    data
  });
}

// 分页查询散文件条目参数
export type IFetchScatterParams = Pick<ICoordinate, 'atCode' | 'atType'>;
// 分页查询散文件条目 已废弃
export function fetchScatteredRecords(data: IPageQuery<IFetchScatterParams>) {
  return request({
    url: `/archives/page-single-file`,
    method: 'post',
    data
  });
}

// 新增条目参数
export interface IDownLevelParams extends ICoordinate {
  commonParams: ICommonParams;
  downLevelId: number;
}

// 查询下级档案条目
export function fetchDownLevelList(data: IPageQuery<IDownLevelParams>) {
  return request({
    url: `archives/page/down-level`,
    method: 'post',
    data
  });
}

// 查询档案分类列表
export function fetchDescCardForm({ atType, atCode, level }: ICoordinate) {
  return request({
    url: `/archives/desc-card/${atType}/${atCode}/${level}`,
    method: 'get'
  });
}

// 条目类型
export type entry = {
  fieldName: string;
  fieldType?: number;
  fieldValue: string;
};

// 新增条目参数
export interface IAddArchiveParams extends ICoordinate {
  entries: entry[];
}

// 增加档案内条目
export function addArchiveItem(data: IAddArchiveParams) {
  return request({
    url: `/archives/`,
    method: 'post',
    data
  });
}

// 新增条目参数
export interface IInsertArchiveParams extends IAddArchiveParams {
  entryId: number;
}

// 插录
export function insertArchiveItem(data: IInsertArchiveParams) {
  return request({
    url: `/archive-arrangement/position-insert`,
    method: 'post',
    data
  });
}

// 分组、排序字段类型
export interface FieldList {
  fieldName: string;
  fieldValue: any;
}
// 生成序号接口参数
export interface IGenSerialNumProps extends ICoordinate {
  commonParams: ICommonParams;
  groupFieldList: FieldList[];
  sortFieldList: FieldList[];
  upLevelId: Key;
}
// 生成序号接口
export function genSerialNum(data: IGenSerialNumProps) {
  return request({
    url: `/archive-arrangement/gen-serial-number`,
    method: 'post',
    data
  });
}

// 查询编辑档案分类列表参数
export interface IEditDescCardFormParams extends ICoordinate {
  entryId: number;
  dbName: string;
}

// 查询编辑档案分类列表
export function fetchEditDescCardForm({
  atType,
  atCode,
  level,
  dbName,
  entryId
}: IEditDescCardFormParams) {
  return request({
    url: `/archives/desc-card/${atType}/${atCode}/${level}/${dbName}/${entryId}`,
    method: 'get'
  });
}

// 编辑条目参数
export interface editArchiveParams extends IAddArchiveParams {
  entryId: number;
  commonParams: ICommonParams;
}

// 增加档案内条目
export function editArchiveItem(data: editArchiveParams) {
  return request({
    url: `/archives/`,
    method: 'put',
    data
  });
}

export interface IFetchArchiveDetailParams extends ICoordinate {
  dbName: string;
  entryId: number;
}
// 增加档案内条目
export function fetchArchiveDetail(params: IFetchArchiveDetailParams) {
  const { atType, atCode, level, dbName, entryId } = params;
  return request({
    url: `/archives/detail/${atType}/${atCode}/${level}/${dbName}/${entryId}`,
    method: 'get'
  });
}

export interface IDeleteArchiveParams extends ICoordinate {
  commonParams: ICommonParams;
  entryIdList: any[];
}
// 删除档案内条目
export function deleteArchiveItem(data: IDeleteArchiveParams) {
  return request({
    url: `/archives/delete`,
    method: 'post',
    data
  });
}

export interface IAddERecordsProps {
  commonParams: ICommonParams;
  coordinate: ICoordinate;
  file_id: number;
  originalFileBeanList: OriginalFileBeanList[];
}

export interface OriginalFileBeanList {
  file_ext: string;
  file_name: string;
  file_path: string;
  file_size: number;
  file_url: string;
  sort_no: number;
}
// 增加电子文件级档案条目
export function addERecords(data: IAddERecordsProps) {
  return request({
    url: `/archives-efile/`,
    method: 'post',
    data
  });
}

// 获取电子文件级档案条目
export function fetchERecords(data: IPageQuery<IDownLevelParams>) {
  return request({
    url: `/archives-efile/page`,
    method: 'post',
    data
  });
}

export interface IDeleteEArchiveParams extends IDeleteArchiveParams {}
// 删除电子文件级档案条目
export function deleteERecords(data: IDeleteEArchiveParams) {
  return request({
    url: `/archives-efile/delete`,
    method: 'post',
    data
  });
}

// 查询不同格式的原文条目
export interface IFetchOriginalFormatParams extends ICoordinate {
  dbName: string;
  eFileId: number;
}
export function fetchOriginalFormat(params: IFetchOriginalFormatParams) {
  const { atType, atCode, level, dbName, eFileId } = params;
  return request({
    url: `/archives-efile/original/${atType}/${atCode}/${level}/${dbName}/${eFileId}`,
    method: 'get'
  });
}

export interface IParsingEEPParams {
  fileUrl: string;
}
// 在线预览 解析sip包接口
export function parsingEEP(data: IParsingEEPParams) {
  return request({
    url: `eep/query/up-level`,
    method: 'post',
    data
  });
}

// 档案征集流转转档案
export interface ITransferArchiveParams {
  mapId: number;
  transferArchiveSourceDTO?: TransferArchiveSourceDTO;
  transferArchiveTargetDTO?: TransferArchiveTargetDTO;
}

export interface TransferArchiveSourceDTO {
  coordinate?: Coordinate;
  dbName?: string;
  movingEntryInfo?: MovingEntryInfo;
}

export interface Coordinate {
  atCode?: number;
  atType?: number;
  level?: number;
}

export interface MovingEntryInfo {
  entryIdList?: any[];
  searchCondition?: string;
}

export interface TransferArchiveTargetDTO {
  coordinate?: Coordinate;
  dbName?: string;
  entryId?: number;
}

export function transferArchive(data: ITransferArchiveParams) {
  return request({
    url: `/archive-moving/transferArchive/`,
    method: 'post',
    data
  });
}
/* 激活 */
export interface IActivateArchiveParams {
  coordinate: Coordinate;
  dbName: string;
  movingEntryInfo: MovingEntryInfo;
}

export function activateArchive(data: IActivateArchiveParams) {
  return request({
    url: `/archive-moving/activate-storage/`,
    method: 'post',
    data
  });
}

/* 销毁 */
export function destroyArchive(data: IActivateArchiveParams) {
  return request({
    url: `/archive-moving/destroy-storage/`,
    method: 'post',
    data
  });
}

/* 暂存 */
export function temporaryArchive(data: IActivateArchiveParams) {
  return request({
    url: `/archive-moving/temporary-storage/`,
    method: 'post',
    data
  });
}

// 生成档号、序号参数
export interface IGenerateNoParams {
  atCode: number;
  atType: number;
  commonParams: ICommonParams;
  entryIdList: any[];
  level: number;
}
// 生成序号
export function generateSortNo(data: IGenerateNoParams) {
  return request({
    url: `/archive-arrangement/gen-serial-number`,
    method: 'post',
    data
  });
}
// 生成档号
export function generateArcNo(data: IGenerateNoParams) {
  return request({
    url: `/archive-arrangement/gen-archive-no`,
    method: 'post',
    data
  });
}
// 生成档号和序号
export function generateArcSortNo(data: IGenerateNoParams) {
  return request({
    url: `/archive-arrangement/gen-serial-number-archive-no`,
    method: 'post',
    data
  });
}
export interface IFetchDetailParams {
  archiveTypeId?: number;
  dbName?: string;
  entryId?: number;
  fondId?: number;
  level?: number;
}
// 逐级向上查询电子文件信息
export function fetchDetail(data: IFetchDetailParams) {
  return request({
    url: `/archives-efile/detail`,
    method: 'post',
    data
  });
}

export interface IFetchRelationParams extends Coordinate {
  commonParamsBean: CommonParamsBean;
  entryId: number;
}
export interface CommonParamsBean {
  dbName: string;
}
// 根据条目id查询互见号关联关系档案条目
export function fetchRelationById(data: IPageQuery<IFetchRelationParams>) {
  return request({
    url: `/archives/page/relation`,
    method: 'post',
    data
  });
}
